package org.format;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class FormatDate2 {
    public static void main(String[] args) throws ParseException {
        var sd = new SimpleDateFormat("yyyy年MM月");
        System.out.println(sd.format(new Date()));

        //将字符串转换为Date 2023-06-09 10:24:30
        var sd2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //format() 格式化返回字符串

        //parse() 将字符串转换为java.util.Date对象例
        Date d = sd2.parse("2023-06-09 10:24:30");
        System.out.println(sd2.format(d));

        //新日期类格式化工具类
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss S EEEE MMMM a");
        //LocalDate LocalTime LocalDateTime
        LocalDateTime now = LocalDateTime.now();
        System.out.println(now.format(df));
        System.out.println(df.format(now));

        //06月13日
        DateTimeFormatter d33 = DateTimeFormatter.ofPattern("MM月dd日");
        System.out.println(d33.format(LocalDate.now()));
        System.out.println(d33.format(LocalDateTime.now()));


        DateTimeFormatter df1 = DateTimeFormatter.ofPattern("yyyy-MM-dd MMMM EEEE");
        LocalDate d1 = LocalDate.now();
        System.out.println(d1.format(df1));

        DateTimeFormatter df2 = DateTimeFormatter.ofPattern("HH:mm:ss S a");
        LocalTime t1 = LocalTime.now();
        System.out.println(t1.format(df2));
        System.out.println(df2.format(t1));

    }
}
